
set WORKDIR=%~1
set BOOKGUID=%~2
set BOOKNAME=%~3

rmdir /s /q "%WORKDIR%\gen"
rmdir /s /q "%WORKDIR%\classes"
del /q %WORKDIR%\ebook.ap_
del /q %WORKDIR%\classes.dex
del /q %WORKDIR%\ebook.apk
del /q %WORKDIR%\ebook_signed.apk
del /q %WORKDIR%\%BOOKNAME%.apk

mkdir "%WORKDIR%\gen"

aapt p -f -m -J %WORKDIR%\gen -M %WORKDIR%\AndroidManifest.xml -S %WORKDIR%\res -I %WORKDIR%\android.jar 2>NUL 1>NUL

mkdir "%WORKDIR%\classes"

javac -encoding Cp1252 -target 1.5 -bootclasspath %WORKDIR%\android.jar %WORKDIR%\src\bookStore\eBook\android\*.java %WORKDIR%\gen\bookStore\eBook\android\book%BOOKGUID%\*.java -d %WORKDIR%\classes 2>NUL 1>NUL

rem cd classes

rem jar cvf ebook.jar *.*

rem cd..

call dx --dex --output=%WORKDIR%\classes.dex %WORKDIR%\classes

aapt package -f -M %WORKDIR%\AndroidManifest.xml -S %WORKDIR%\res -I %WORKDIR%\android.jar -F %WORKDIR%\ebook.ap_ 2>NUL 1>NUL

call apkbuilder %WORKDIR%\ebook.apk -u -z %WORKDIR%\ebook.ap_ -f %WORKDIR%\classes.dex -rf %WORKDIR%\src

rem aapt add ebook.apk classes.dex

java -jar %WORKDIR%\signapk.jar %WORKDIR%\certificate.pem %WORKDIR%\key.pk8 %WORKDIR%\ebook.apk %WORKDIR%\ebook_signed.apk 2>NUL 1>NUL

zipalign -v 4 %WORKDIR%\ebook_signed.apk %WORKDIR%\%BOOKNAME%.apk 2>NUL 1>NUL

del /q %WORKDIR%\ebook.ap_
del /q %WORKDIR%\classes.dex
del /q %WORKDIR%\ebook.apk
del /q %WORKDIR%\ebook_signed.apk
rmdir /s /q "%WORKDIR%\gen"
rmdir /s /q "%WORKDIR%\classes"
